package com.ssy.lingxi.message.serviceimpl;

import com.ssy.lingxi.common.constant.basic.UserLoginSourceEnum;
import com.ssy.lingxi.message.service.IMemberMessageService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 站内消息服务实现类
 * @author yzc
 * @version 2.0.0
 * @date 2020/10/27
 */
@Service
public class InSiteMessageService {
    @Resource
    private IMemberMessageService memberMessageService;
    @Resource
    private MessageEventService messageEventService;

    /**
     * 查询未读消息数量
     * @param source
     * @param memberId
     * @param roleId
     */
    @Async
    public void countUnreadMessageCount(Integer source, Long memberId, Long roleId, Long userId) {
        if (UserLoginSourceEnum.BUSINESS_WEB.getCode().equals(source)) {
            // 填充消息
            memberMessageService.pullMainMessage(memberId, roleId, userId);

            // 推送未读消息数
            messageEventService.onMessage(memberId, roleId, userId);
        } else if (UserLoginSourceEnum.BUSINESS_MANAGEMENT_PLATFORM.getCode().equals(source)) {
            // 推送未读消息数
            messageEventService.onPlatformMessage();
        }
    }
}
